package gsp420;
public class Vector2D
{
	double x, y;
	public Vector2D(double x, double y)
	{
		this.x = x;
		this.y = y;
	}
	public Vector2D(){}
	public static void main(String[] args)
	{
		Vector2D v = new Vector2D(Math.random(), Math.random());
		double len = v.length();
		System.out.println(len);
		v.normalize();
		len = v.length();
		if(len < 0.99999 || len > 1.000001)
			System.out.println("FAIL!");
		else
			System.out.println(len);
	}
	public void divide(double a_value)
	{
		x /= a_value;
		y /= a_value;
	}
	public void normalize()
	{
		divide(length());
	}
	public double length()
	{
		return Math.sqrt(x*x+y*y);
	}
	public String toString()
	{
		return "("+x+","+y+")";
	}
	public Vector2D product(double m)
	{
		return new Vector2D(x*m, y*m);
	}
	public void add(Vector2D v)
	{
		x += v.x;
		y += v.y;
	}
	public double distance(Vector2D p)
	{
		double dx = x-p.x;
		double dy = y-p.y;
		return Math.sqrt(dx*dx+dy*dy);
	}
	public void set(double x, double y)
	{
		this.x = x;
		this.y = y;
	}
	public void multiply(double m)
	{
		x *= m;
		y *= m;
	}
	public Vector2D sum(Vector2D v)
	{
		return new Vector2D(x+v.x, y+v.y);
	}
}